package com.bjesc_b2c.app.appraiset.mvp.model.impl;

import android.content.Context;

import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.model.AppraiserModel;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;
import java.util.List;

import master_bean.AppraiserBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/5/31.
 */

public class AppraiserModelImpl implements AppraiserModel {

    private CallBack callBack;
    public AppraiserModelImpl(CallBack callBack){
        this.callBack = callBack;
    }
    @Override
    public void getAllAppraiser(Context context) {
        RxRequest.request(ShowType.SHOW, RxRequest.getClient(context, new MapUtil().build()).create(IApiActivityRequest.class).getAllAppraiser(),
                new BaseSubscriber<TokenBean<List<AppraiserBean>>>(context) {
                    @Override
                    public void onSuccess(TokenBean<List<AppraiserBean>> o) {
                        if(callBack!= null){
                            callBack.callbackDate(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {

                    }
                });
    }

    @Override
    public void moveOrdersTrack(Context context, String dispatch_id, String toId, String content,int type) {
        HashMap<String, Object> build = new MapUtil()
                .put("dispatch_id", dispatch_id)
                .put("to", toId)
                .put("content", content)
                .put("type", type)
                .build();
        RxRequest.request(ShowType.SHOW, RxRequest.getClient(context, build).create(IApiActivityRequest.class).moveOrdersTrack(),
                new BaseSubscriber<TokenBean>(context) {
                    @Override
                    public void onSuccess(TokenBean o) {
                        if(callBack!= null){
                            callBack.callbackInfo(o);
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {

                    }
                });
    }
    public interface CallBack{
        void callbackDate(List<AppraiserBean> listbean);

        void callbackInfo(TokenBean bean);
    }

}
